package com.lagou.edu.controller;

import com.lagou.edu.service.LoginService;
import com.lagou.edu.service.TokenService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * @author bobcheng
 * @date 2020/7/2
 */
@RestController
@Slf4j
public class LoginController {

    @Autowired
    private LoginService loginService;
    @Autowired
    private TokenService tokenService;

    @GetMapping("/login/{email}/{password}")
    public boolean login(@PathVariable String email, @PathVariable String password, HttpServletResponse response) {
        boolean login = loginService.login(email, password);
        if (login) {
            tokenService.addToken(email, response);
        }
        return login;
    }

}
